package com.wang.demo.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.entity.PageResult;
import com.wang.demo.convert.SysUserPoConvert;
import com.wang.demo.entity.dto.UserDto;
import com.wang.demo.entity.po.UserPo;
import com.wang.demo.dao.UserDao;
import com.wang.demo.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userMapper;


    @Override
    public int addUser(UserDto userDto) {
        UserPo userPo = new UserPo();
        BeanUtils.copyProperties(userDto, userPo);
        int count = userMapper.insert(userPo);
        return count;
    }

    @Override
    public int deleteUser(Long id) {
        int count = userMapper.deleteById(id);
        return count;
    }

    @Override
    public PageResult<UserPo> getUserPage(UserDto userDto) {
         IPage<UserPo> userPoPage = new Page<>(userDto.getCurrent(), userDto.getSize());
         IPage<UserPo> userPoPage1 = userMapper.getUserPage(userPoPage);
         PageResult<UserPo> userPoPageResult = new PageResult<>();
         userPoPageResult.loadData(userPoPage1);
         return userPoPageResult;
    }

    @Override
    public UserDto getUserById(Long id) {
        UserPo userPo = userMapper.selectById(id);
        UserDto userDto = SysUserPoConvert.INSTANCE.convertPoToDto(userPo);
        return userDto;
    }

    @Override
    public String AspectTest() {
        return "成功";
    }
}